package org.sdp.pearproject.service.impl;


import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import org.sdp.pearproject.dto.request.*;
import org.sdp.pearproject.dto.response.*;
import org.sdp.pearproject.dao.domain.*;
import org.sdp.pearproject.service.*;
import org.sdp.pearproject.service.custom.*;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

/**
 * @ClassName: TaskServiceImpl
 * @Description:
 * @Author: SDP
 * @Date: 2022-07-18
 * @Version: 1.0
 * Table: pear_task
 * Comment:
 * 任务表
 */
@Service
public class TaskServiceImpl extends TaskServiceCustomImpl implements TaskService {

    static {
        beanClassNameMap.put("task", "taskServiceImpl");
        listMethodNameMap.put("task", "listTask");
        listMethodParameterClassNameMap.put("task", "TaskQueryRequest");
        updateMethodNameMap.put("task", "updateTask");
        updateMethodParameterClassNameMap.put("task", "TaskUpdateRequest");
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public Integer addTask(TaskAddRequest request) throws Exception {
        super.fixRequest("task", "add", request);
        return super.addTask(request);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public Integer updateTask(TaskUpdateRequest request) throws Exception {
        Task record = null;
        record = taskMapper.selectByPrimaryKey(
          request.getId(),
          request.getProjectCode()
        );
        super.fixRequest("task", "update", request, record);
        return super.updateTask(request);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public Integer deleteTask(TaskDeleteRequest request) throws Exception {
        if (needCheckDeleteList(request)) {
            List<Task> list = null;
            if(true) {
                throw new Exception("not implement");
            }
            fixRequest("task", "delete", request, list);
        } else {
            fixRequest("task", "delete", request);
        }
        return super.deleteTask(request);
    }

    @Override
    public TaskQueryResponse queryTask(TaskQueryRequest request) throws Exception {
        super.checkNonNull(request.getId(), "id");
        super.checkNonNull(request.getProjectCode(), "项目编号");
        TaskQueryResponse result = super.queryTask(request);
        checkResult("task", "query", request, result);
        return result;
    }

    @Override
    public List<TaskQueryResponse> listTask(TaskQueryRequest request) throws Exception {
        List<TaskQueryResponse> list = super.listTask(request);
        checkResult("task", "list", request, list);
        return list;
    }

    @Override
    public Integer countTask(TaskQueryRequest request) throws Exception {
        clearPageInfo(request);
        super.fixRequest("task", "count", request);
        return super.countTask(request);
    }

    @Override
    public BaseStatResponse statTask(TaskQueryRequest request) throws Exception {
        clearPageInfo(request);
        super.fixRequest("task", "stat", request);
        return super.statTask(request);
    }

}
